package com.tanhua.server.controller;


import com.tanhua.model.vo.*;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /*
     *  搜附近
     *    请求方式和请求链接 : GET    /search
     *    请求参数: Query  gender distance（半径）
     *    返回值:  list<NearUserVo>
     * */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){

        List<NearUserVo> vo=tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vo);
    }

    /*
     * 今日佳人
     *    请求方式和请求链接 : GET  /todayBest
     *    请求参数:  无
     *    返回值: TodayBest
     * */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }
    /*
     * 推荐朋友 --首页推荐
     *    请求方式和请求链接 : GET / recommendation
     *    请求参数:query RecommendUserDto
     *    返回值:PageResult
     * */

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {

        PageResult result = tanhuaService.recommendation(dto);

        return ResponseEntity.ok(result);
    }

    /*
     *  佳人信息
     *    请求方式和请求链接 : GET /:id(用户id)/personalInfo
     *    请求参数:用户id
     *    返回值: TodayBest
     * */
    @GetMapping("/{userId}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("userId") Long userId) {

        TodayBest best = tanhuaService.personalInfo(userId);

        return ResponseEntity.ok(best);

    }

    /*
     * 查询陌生人问题
     *    请求方式和请求链接 : GET  /strangerQuestions
     *    请求参数: userId
     *    返回值: string 陌生人问题
     * */

    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {

        String context = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(context);
    }

    /*
     *  回复陌生人问题
     *    请求方式和请求链接 : POST  /strangerQuestions
     *    请求参数: Body: userId,reply(回复数据)
     *    返回值: 无
     * */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map){

        //获得请求数据
        String reply =(String) map.get("reply");
        String str = map.get("userId").toString();
        Long userId = Long.valueOf(str);
        tanhuaService.reply(reply,userId);

        return ResponseEntity.ok(null);
    }

    //卡片
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<CardVo> vos = tanhuaService.cards();
        return ResponseEntity.ok(vos);
    }

    //喜欢
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId){
            this.tanhuaService.likeUser(likeUserId);
            return ResponseEntity.ok(null);

    }

    //不喜欢
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId) {
            this.tanhuaService.disLikeUser(likeUserId);
            return ResponseEntity.ok(null);
    }
}
